// 2013-9-11下午10:51:50  net.betou.trade.main.dao.role.impl.SystemRoleDaoImpl.java

package net.betou.trade.main.dao.role.impl;

import java.util.List;

import net.betou.common.hibernate3.Finder;
import net.betou.trade.entity.main.Role;
import net.betou.trade.main.dao.role.SystemRoleDao;

import org.springframework.stereotype.Repository;

/**
 * 
 * @author 叶装装
 */
@Repository
public class SystemRoleDaoImpl extends DaoImpl implements SystemRoleDao{

	@SuppressWarnings( "unchecked" )
	public List< Role > findList( Boolean manager, Boolean allowRead, Integer level, String searchProperty, String searchValue, String orderProperty, String orderDirection ) {
		
		Finder f = Finder.create( "from Role bean where bean.manager=:manager " );
		f.setParam( "manager", manager );
		
		if( level != null ){
			f.append( " and bean.level >=:level " );
			f.setParam( "level", level );
		}
		
		if( allowRead != null ){
			f.append( " and bean.allowRead=:allowRead" );
			f.setParam( "allowRead", allowRead );
		}
		
		createSearch( f, searchProperty, searchValue );
		createOrder( f, orderProperty, orderDirection, "id" );
		
		return find( f, true );
	}
	
	@SuppressWarnings( "unchecked" )
	public List< Role > findList( Integer level, Integer adminId ) {
		Finder f = Finder.create( "from Role bean where bean.admin.id=:id " );
		f.setParam( "id", adminId );

		if( level != null ){
			f.append( " and bean.level >=:level " );
			f.setParam( "level", level );
		}

		return find( f, true );
	}
}
